﻿// -----------------------------------------------------------------------
// <copyright file="Common.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Text;
using System.Security.Cryptography;

namespace Infrastructure.Utility
{

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Common
    {
        public static string ConvertToMD5String( string sSourceString )
        {
            string hashString = string.Empty;

            UTF8Encoding utf8Encode = new UTF8Encoding();
            byte[] bytes = utf8Encode.GetBytes( sSourceString );

            // encrypt bytes
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] hashBytes = md5.ComputeHash( bytes );

            // Convert the encrypted bytes back to a string (base 16)
            for ( int i = 0; i < hashBytes.Length; i++ )
            {
                hashString += Convert.ToString( hashBytes[ i ], 16 ).PadLeft( 2, '0' );
            }

            return hashString.PadLeft( 32, '0' );
        }
    }
}
